﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Diagnostics.CodeAnalysis;

namespace Steve
{
    public enum MimeType
    {
        Application,
        Audio,
        Image,
        Message,
        Model,
        Multipart,
        Text,
        Video
    }

    [DataContract]
    [Serializable]
    public sealed class ContentNodeMetadata : IDirectoryNodeMetadata
    {
        public ContentNodeMetadata(string path, Guid id)
        {
            Id = id;
            Path = path;
        }

        [DataMember]
        public Guid Id { get; set; }
        [DataMember]
        public string Path { get; set; }

        bool IDirectoryNodeMetadata.IgnoreQueryString
        {
            get { return true; }
        }
    }

    [DataContract]
    [Serializable]
    public sealed class Content : RevisedObject, IIntegrationObject
    {
        //header data
        [DataMember] 
        public Guid Id { get; set; }
        [DataMember]
        public string Language { get; set; }
        [DataMember]
        public string SystemName { get; set; }
        [DataMember] 
        public string ExternalId { get; set; }
        [DataMember]
        public string Path { get; set; }
        [DataMember]
        public string ContentTypeName { get; set; }
        [DataMember]
        public Guid? SiteUrlId { get; set; }
        [DataMember]
        public int? LatestApprovedRevisionNumber { get; set; }

        //revision data
        [DataMember]
        public int? Height { get; set; }
        [DataMember]
        public int? Width { get; set; }
        [DataMember] 
        public string Title { get; set; }
        [DataMember]
        public string Teaser { get; set; }
        [DataMember]
        public DateTime? PublicationDate { get; set; }
        [DataMember]
        public string Publisher { get; set; }
        [DataMember]
        public DateTime? ApprovalDate { get; set; }
        [DataMember]
        public Guid? ApprovalMembershipId { get; set; }
        [DataMember]
        public MimeType? MimeType { get; set; }
        [DataMember]
        public string MimeSubtype { get; set; }
        [DataMember]
        public Guid? ContentDataId { get; set; }
        [DataMember]
        public string Author { get; set; }
        [DataMember]
        public string SiteName { get; set; }
        [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")]
        [DataMember]
        public string Url { get; set; }
        [DataMember]
        public bool IsSecure { get; set; }
        [DataMember]
        public string DefaultAuthority { get; set; }

        //helper properties
        public bool IsLatest { get { return LatestRevisionNumber == RevisionNumber; } }
        public bool IsLatestApproved { get { return LatestApprovedRevisionNumber == RevisionNumber; } }

        [SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
        public string FullMimeType
        {
            get
            {
                if (MimeType == null || string.IsNullOrWhiteSpace(MimeSubtype)) return null;

                return MimeType.Value.ToString("g").ToLowerInvariant() + '/' + MimeSubtype.ToLowerInvariant();
            }
        }
    }
}
